package br.com.java.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import br.com.java.dao.ArquivoDAO;
import br.com.java.entities.Aluno;
import br.com.java.entities.Arquivo;

@Repository
public class ArquivoDAOImpl extends GenericDAOImpl<Arquivo, Long> implements Serializable, ArquivoDAO {

	private static final long serialVersionUID = -3334421135033851801L;
	
	@SuppressWarnings("unchecked")
	public List<Arquivo> retrieveByAluno(Aluno aluno) {
		
		Session session = sessionFactory.openSession();
		Criteria criteria = session.createCriteria(Arquivo.class);
		
		if (aluno != null)
			criteria.add(Restrictions.eq("aluno", aluno)); 
		
		List<Arquivo> arquivos = criteria.list();
		
		return arquivos;
    }

}
